package com.flowerplus.store.common.data.utils;

import java.util.List;

/**
 * Created by z on.
 * Des:循环根据阀值查找值
 * Date: 2017/4/5
 */

public class ComparatorUtil {


    /**
     * 查找
     *
     * @param list       数据集
     * @param comparator 阀值
     * @return
     */
    public static <T> T find(List<T> list, Comparator<T> comparator) {
        if (list == null || list.isEmpty()) {
            return null;
        }
        for (int i = 0; i < list.size(); i++) {
            T t = list.get(i);
            boolean compare = comparator.compare(t);
            if (compare) {
                return t;
            }
        }
        return null;
    }

    public interface Comparator<T> {
        boolean compare(T o1);
    }
}
